﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using hpcpdi.DataAccess.Interface;
using hpcpdi.Entities;
using hpcpdi.Entities.DTO;
using hpcpdi.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace hpcpdi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TargetController : ControllerBase
    {
        private readonly ITargetRepository _targetRepository;
        public TargetController(ITargetRepository targetRepository)
        {
            _targetRepository = targetRepository;
        }
        /// <summary>
        /// 获取预警车辆数
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/target/earlywarningcount")]
        public async Task<ResultModel<int>> EarlyWarningCount()
        {
            //待修改 预警车辆，指目标自身发生突然停车、变道、逆行、慢行等预警事件的目标。

            Task<int> Retrograde =  _targetRepository.GetRetrogradeTarget();
            Task<int> LaneChange =  _targetRepository.GetLaneChangeTarget();
            Task<int> SlowMove = _targetRepository.GetSlowMoveTarget();
            Task<int> Stop = _targetRepository.GetStopTarget();
            return ResultModel.Success(Retrograde.Result + LaneChange.Result+ SlowMove.Result+ Stop.Result);
        }
        /// <summary>
        /// 全程总车辆
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/target/TotalTarget")]
        public async Task<ResultModel<int>> TotalTarget()
        {
         return  ResultModel.Success(await _targetRepository.GetTotalTarget());
        }
        /// <summary>
        /// 获取速度
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/target/Speed")]
        public ResultModel<speedVM> GetSpeed()
        {
           return ResultModel.Success(_targetRepository.GetSpeed());
        }
        /// <summary>
        /// 今日突然变道
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/target/SuddenlyCL")]
        public ResultModel<SuddenlyCLVM> GetSuddenlyCL()
        {
            SuddenlyCLVM vm = new SuddenlyCLVM();
            vm.SuddenlyCLCome = _targetRepository.GetSuddenlyCLCome();
            vm.SuddenlyCLGo = _targetRepository.GetSuddenlyCLGo();
            vm.SuddenlyCL = vm.SuddenlyCLCome + vm.SuddenlyCLGo;
            return ResultModel.Success(vm);
        }
        /// <summary>
        /// 今日突然停车
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/target/SuddenlyStop")]
        public ResultModel<SuddenlyStopVM> GetSuddenlyStop()
        {
            SuddenlyStopVM vm = new SuddenlyStopVM();
            vm.SuddenlyStopCome = _targetRepository.GetSuddenlyStopCome();
            vm.SuddenlyStopGo = _targetRepository.GetSuddenlyStopGo();
            vm.SuddenlyStop = vm.SuddenlyStopCome + vm.SuddenlyStopGo;
            return ResultModel.Success(vm);
        }
        /// <summary>
        /// 预警分布
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/target/earlyWarning")]
        public ResultModel<earlyWarningVM> GetearlyWarning()
        {
            earlyWarningVM vm = new earlyWarningVM();
            vm= _targetRepository.GetEarlyWarning();
            vm.TotalEarlyWarning = vm.SuddenlyStop + vm.SuddenlyCL + vm.SlowMoving + vm.Restrograde + vm.OtherWorning;
            return ResultModel.Success(vm);
        }
        /// <summary>
        /// 历史通行量
        /// </summary>
        /// <param name="days"></param>
        /// <returns></returns>
        [HttpGet("/api/target/TrafficPassValue")]
        public ResultModel<IEnumerable<trafficpass_his>> GetTrafficPassValue(int days)
        {
           return ResultModel.Success(_targetRepository.GetTrafficPassValue(days));
        }
    }
}
